package com.power.sifa.correction.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.alibaba.excel.util.ListUtils;
import com.power.sifa.approve.service.ProcessApproveService;
import com.power.sifa.correction.model.pojo.bo.AutoEndCaseBO;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * @author xiongzhiwen
 * @version 1.0
 * @description: TODO
 * @date 2024/4/26 13:41
 */

@Slf4j
public class AutoEndCaseListener extends AnalysisEventListener<AutoEndCaseBO> {


    /**
     * crc_personService
     */
    private final ProcessApproveService processApproveService;

    private List<AutoEndCaseBO> cacheList = ListUtils.newArrayListWithExpectedSize(100);

    public AutoEndCaseListener(ProcessApproveService processApproveService) {
        this.processApproveService = processApproveService;
    }

    @Override
    public void invoke(AutoEndCaseBO autoEndCaseBO, AnalysisContext analysisContext) {
        cacheList.add(autoEndCaseBO);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        this.cacheList.stream().forEach(el -> {
            this.processApproveService.autoEndCase(el);
        });
    }
}
